/* -----------------------------------------------------------------------------
 * PROJECT    : net.lwf
 * FILE       : RoundingAction.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Nov 14, 2008       Raghu Sarraff			       Created
 */
package net.lwf.web.struts.action.maths.number;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lwf.handler.IProcessHandler;
import lwf.web.struts.action.constant.IActionConstant;
import net.lwf.entity.QuestionInfo;
import net.lwf.handler.math.number.RoundingProcessHandler;
import net.lwf.string.util.StringManipulator;
import net.lwf.web.constant.IPageTitle;
import net.lwf.web.struts.action.LwfWorksheetAction;
import net.lwf.web.struts.action.LwfWorksheetActionForm;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


/**
 * Type the class description here
 *  
 */
public class RoundingAction extends LwfWorksheetAction {
	
	public ActionForward home(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		//Set form data
		LwfWorksheetActionForm aform = (LwfWorksheetActionForm) form;
		aform.setAskQuestion(false);
		return mapping.findForward("display");
	} //home	
	
	public ActionForward generate(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		RoundingProcessHandler handler = (RoundingProcessHandler) getHandler(request);
		QuestionInfo qinfo = handler.generateSingle();
		//Set the question data
		setQuestionData(request, qinfo);
		//Set form data
		LwfWorksheetActionForm aform = (LwfWorksheetActionForm) form;
		aform.setQuestion(qinfo.getQuestion());
		aform.setAskQuestion(true);
		aform.setQuestionNumber(getQuestionNumber(request));
		aform.setInstructionText(qinfo.getPlaceHolder().toString());
		return mapping.findForward("display");
	}
	
	@Override
	public String getPageTitle() {
		return IPageTitle.NUMBER_ROUNDING;
	}

	@Override
	public String getMainTitle() {
		return "Numbers";
	}

	@Override
	public String getPdfLink() {
		return IActionConstant.ROUNDING_PDF_LINK;
	}

	@Override
	public String getQuizLink() {
		return IActionConstant.ROUNDING_QUIZ_LINK;
	}
	
	@Override
	public IProcessHandler getHandler(HttpServletRequest request) {
		return new RoundingProcessHandler(getGrade());
	}

}

